```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java锁膨胀升级机制深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f9fafb;
            color: #1f2937;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
            color: white;
        }
        .card {
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        .card:hover {
            transform: translateY(-4px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .section-title {
            position: relative;
            padding-left: 16px;
        }
        .section-title:before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            height: 60%;
            width: 4px;
            background: linear-gradient(to bottom, #3b82f6, #10b981);
            border-radius: 2px;
        }
        .first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 1;
            margin-right: 0.5rem;
            margin-top: 0.2rem;
            color: #3b82f6;
            font-weight: bold;
        }
        .diagram-container {
            background: white;
            border-radius: 12px;
            padding: 1.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1);
        }
        .icon-box {
            width: 50px;
            height: 50px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 1rem;
            flex-shrink: 0;
        }
        .feature-card {
            border-left: 4px solid;
            transition: all 0.3s ease;
        }
        .feature-card:hover {
            transform: translateX(4px);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Java锁膨胀升级机制深度解析</h1>
                    <p class="text-xl text-blue-100 mb-8">探索高并发环境下锁状态演变的奥秘与优化之道</p>
                    <div class="flex flex-wrap gap-4">
                        <span class="px-4 py-2 bg-blue-600 rounded-full text-sm font-medium">并发编程</span>
                        <span class="px-4 py-2 bg-blue-600 rounded-full text-sm font-medium">JVM优化</span>
                        <span class="px-4 py-2 bg-blue-600 rounded-full text-sm font-medium">性能调优</span>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="diagram-container">
                        <div class="mermaid">
                            graph TD
                                A[无锁状态] -->|线程首次访问| B[偏向锁]
                                B -->|第二个线程访问| C[轻量级锁]
                                C -->|竞争加剧| D[重量级锁]
                                D -->|锁释放| A
                                style A fill:#f0fdf4,stroke:#4ade80
                                style B fill:#ecfdf5,stroke:#10b981
                                style C fill:#f0f9ff,stroke:#0ea5e9
                                style D fill:#fee2e2,stroke:#ef4444
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="card p-8 md:p-10">
                <div class="flex items-start mb-8">
                    <div class="icon-box bg-blue-100 text-blue-600">
                        <i class="fas fa-info-circle text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-4">什么是锁膨胀升级</h2>
                        <p class="text-gray-700 mb-4">随着计算机硬件性能的提升和并发处理需求的增加，多线程编程已经成为现代软件开发的常态。在Java中，锁机制是保障多线程环境下数据一致性的重要手段。</p>
                    </div>
                </div>
                
                <div class="relative mb-8">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1723605686697-6874da7c-a748-480c-b011-561fb801e352.png" 
                         alt="锁膨胀升级示意图" 
                         class="w-full rounded-lg shadow-md">
                    <div class="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black to-transparent p-4 text-white rounded-b-lg">
                        <p class="text-sm opacity-90">Java锁状态转换示意图</p>
                    </div>
                </div>
                
                <div class="prose max-w-none">
                    <p><span class="first-letter">锁</span>膨胀升级指的是在多线程竞争激烈的场景下，锁从一种轻量级状态逐步升级为更重的状态，从而引发性能下降的现象。在Java中，锁通常有三种状态：偏向锁、轻量级锁和重量级锁。偏向锁和轻量级锁在低竞争环境下能够提供较高的性能，但当竞争变得激烈时，锁会逐渐升级为重量级锁，以保证线程的安全性。</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Basic Concepts Section -->
    <section class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 text-center section-title">锁的基本概念</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="card p-6 feature-card border-blue-500">
                    <div class="flex items-center mb-4">
                        <div class="icon-box bg-blue-100 text-blue-600">
                            <i class="fas fa-lock text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">锁的作用</h3>
                    </div>
                    <p class="text-gray-700">锁的主要作用是确保在并发环境下，临界区的代码能够安全地执行。通过加锁，只有持有锁的线程能够进入临界区，而其他线程必须等待锁的释放，避免了多个线程同时修改同一数据的情况。</p>
                </div>
                
                <div class="card p-6 feature-card border-green-500">
                    <div class="flex items-center mb-4">
                        <div class="icon-box bg-green-100 text-green-600">
                            <i class="fas fa-exchange-alt text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">锁的状态和升级</h3>
                    </div>
                    <p class="text-gray-700">在Java中，锁有不同的状态，并且锁的状态可以在运行时根据竞争情况进行升级。锁的状态包括偏向锁、轻量级锁和重量级锁。这种锁的升级机制是为了在不同的并发场景下平衡性能和开销。</p>
                </div>
            </div>
            
            <div class="card p-8">
                <div class="mb-8">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1723605722745-dcbceb93-a49b-4868-a267-c91ea5582fae.png" 
                         alt="锁类型示意图" 
                         class="w-full rounded-lg shadow-md">
                </div>
                
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">锁的基本类型</h3>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="p-4 bg-blue-50 rounded-lg">
                        <h4 class="font-medium text-blue-700 mb-2 flex items-center">
                            <i class="fas fa-user-lock mr-2"></i> 互斥锁 (Mutex)
                        </h4>
                        <p class="text-gray-700">最基本的锁类型，又称为排他锁。在某一时刻，只有一个线程可以持有互斥锁。其他线程必须等待该锁被释放后才能获取锁。</p>
                    </div>
                    
                    <div class="p-4 bg-green-50 rounded-lg">
                        <h4 class="font-medium text-green-700 mb-2 flex items-center">
                            <i class="fas fa-users mr-2"></i> 读写锁 (ReadWriteLock)
                        </h4>
                        <p class="text-gray-700">一种特殊的锁机制，允许多个线程同时读共享资源(读锁)，但在写操作时(写锁)只允许一个线程操作。适合读多写少场景。</p>
                    </div>
                    
                    <div class="p-4 bg-purple-50 rounded-lg">
                        <h4 class="font-medium text-purple-700 mb-2 flex items-center">
                            <i class="fas fa-sync-alt mr-2"></i> 自旋锁 (Spinlock)
                        </h4>
                        <p class="text-gray-700">在等待锁时不会阻塞线程，而是让线程在获取锁之前持续占用CPU资源。适用于锁等待时间很短的场景。</p>
                    </div>
                    
                    <div class="p-4 bg-yellow-50 rounded-lg">
                        <h4 class="font-medium text-yellow-700 mb-2 flex items-center">
                            <i class="fas fa-recycle mr-2"></i> 递归锁 (Reentrant Lock)
                        </h4>
                        <p class="text-gray-700">允许同一线程多次获取同一锁，而不会发生死锁。Java中的 `ReentrantLock` 就是递归锁的一个典型实现。</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Definition Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="card p-8 md:p-10">
                <div class="flex items-start mb-8">
                    <div class="icon-box bg-purple-100 text-purple-600">
                        <i class="fas fa-book text-2xl"></i>
                    </div>
                    <div>
                        <h2 class="text-2xl font-bold mb-4">锁膨胀升级的定义</h2>
                        <p class="text-gray-700">锁膨胀升级（Lock Inflation/Lock Escalation）是指在多线程环境下，由于线程竞争的激化，锁从一种较轻的状态逐步升级到更重的状态，从而导致系统开销增加、性能下降的现象。</p>
                    </div>
                </div>
                
                <div class="relative mb-8">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1723605757862-b8b24038-c9b2-4c0e-81ec-62d260bd0d45.png" 
                         alt="锁膨胀升级详细过程" 
                         class="w-full rounded-lg shadow-md">
                </div>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">锁的状态和升级路径</h3>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <div class="bg-green-100 text-green-800 rounded-full w-6 h-6 flex items-center justify-center flex-shrink-0 mt-1 mr-3">
                                    <i class="fas fa-leaf text-xs"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium">偏向锁 (Biased Locking)</h4>
                                    <p class="text-sm text-gray-600">锁的初始状态，适用于无竞争或极低竞争的场景。锁的持有者可以反复进入临界区而不需要实际的同步操作。</p>
                                </div>
                            </div>
                            
                            <div class="flex items-start">
                                <div class="bg-blue-100 text-blue-800 rounded-full w-6 h-6 flex items-center justify-center flex-shrink-0 mt-1 mr-3">
                                    <i class="fas fa-feather-alt text-xs"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium">轻量级锁 (Lightweight Locking)</h4>
                                    <p class="text-sm text-gray-600">当第二个线程试图获取已被偏向的锁时，锁会膨胀为轻量级锁。使用CAS操作来尝试获取锁，适用于少量竞争的场景。</p>
                                </div>
                            </div>
                            
                            <div class="flex items-start">
                                <div class="bg-red-100 text-red-800 rounded-full w-6 h-6 flex items-center justify-center flex-shrink-0 mt-1 mr-3">
                                    <i class="fas fa-weight-hanging text-xs"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium">重量级锁 (Heavyweight Locking)</h4>
                                    <p class="text-sm text-gray-600">当多个线程激烈争夺同一把锁时，轻量级锁会膨胀为重量级锁。通过操作系统的同步机制实现，线程会被阻塞。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">锁膨胀升级的触发条件</h3>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-bolt text-yellow-500 mr-2 mt-1"></i>
                                <span>线程争用：多个线程频繁争夺同一把锁</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-times-circle text-red-500 mr-2 mt-1"></i>
                                <span>锁获取失败：CAS操作失败且检测到竞争</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-code-branch text-purple-500 mr-2 mt-1"></i>
                                <span>递归锁的使用：线程持有轻量级锁后再次进入相同同步块</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Causes Section -->
    <section class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 text-center section-title">锁膨胀升级的原因</h2>
            
            <div class="card p-8">
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-2xl font-semibold mb-6 text-gray-800">线程竞争激烈</h3>
                        
                        <div class="space-y-6">
                            <div>
                                <h4 class="font-medium mb-2 text-blue-700">初始状态：偏向锁</h4>
                                <p class="text-gray-700">偏向锁是JVM为优化无竞争或低竞争场景而设计的轻量级锁。当另一个线程尝试获取同一个锁时，偏向锁将会撤销，并升级为轻量级锁。</p>
                            </div>
                            
                            <div>
                                <h4 class="font-medium mb-2 text-blue-700">轻量级锁的膨胀</h4>
                                <p class="text-gray-700">在高并发场景下，多个线程同时竞争轻量级锁，导致大量CAS操作失败。每次CAS失败，JVM都会意识到竞争的加剧，并逐步将锁升级为重量级锁。</p>
                            </div>
                            
                            <div>
                                <h4 class="font-medium mb-2 text-blue-700">重量级锁的触发</h4>
                                <p class="text-gray-700">重量级锁通过操作系统的同步原语（如互斥量）来实现，线程在竞争失败时将被阻塞，直到锁被释放。尽管确保线程安全，但代价是频繁的上下文切换。</p>
                            </div>
                        </div>
                    </div>
                    
                    <div>
                        <h3 class="text-2xl font-semibold mb-6 text-gray-800">线程数的增加</h3>
                        <p class="text-gray-700 mb-6">在多线程环境中，随着线程数量的增加，线程之间对共享资源的争夺也会加剧。即使轻量级锁已经优化了锁的获取机制，但当大量线程同时争抢同一个锁时，锁膨胀升级仍然不可避免。</p>
                        
                        <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4">
                            <div class="flex">
                                <div class="flex-shrink-0">
                                    <i class="fas fa-exclamation-triangle text-yellow-500 mt-1"></i>
                                </div>
                                <div class="ml-3">
                                    <h4 class="text-sm font-medium text-yellow-800">恶性循环</h4>
                                    <p class="text-sm text-yellow-700 mt-1">当线程数过多时，锁的膨胀升级可能会陷入一种恶性循环。线程争抢锁导致锁升级，锁升级又导致更多的线程阻塞，阻塞的线程一旦被唤醒又会重新争抢锁，从而进一步加剧竞争。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="mt-12">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">锁的粒度不合理</h3>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-white p-6 rounded-lg border border-gray-200">
                            <h4 class="font-medium mb-3 text-red-600">粗粒度锁的问题</h4>
                            <p class="text-gray-700">粗粒度锁覆盖了较大的代码块或较多的共享资源。尽管可以减少锁的数量，但在高并发场景下，粗粒度锁往往会成为竞争的热点，导致锁膨胀升级。</p>
                        </div>
                        
                        <div class="bg-white p-6 rounded-lg border border-gray-200">
                            <h4 class="font-medium mb-3 text-green-600">细粒度锁的挑战</h4>
                            <p class="text-gray-700">细粒度锁虽然可以降低锁的竞争，但如果设计不当，仍然可能导致锁膨胀。例如，细粒度锁的数量过多会增加锁管理的复杂性，可能引发死锁。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Impact Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 text-center section-title">锁膨胀升级的影响</h2>
            
            <div class="card p-8">
                <div class="grid md:grid-cols-3 gap-6 mb-8">
                    <div class="p-6 bg-red-50 rounded-lg">
                        <div class="flex items-center mb-4">
                            <div class="icon-box bg-red-100 text-red-600">
                                <i class="fas fa-tachometer-alt"></i>
                            </div>
                            <h3 class="text-xl font-semibold ml-3">性能下降</h3>
                        </div>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-exchange-alt text-red-500 mr-2 mt-1"></i>
                                <span>上下文切换的增加</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-times-circle text-red-500 mr-2 mt-1"></i>
                                <span>CAS失败的成本</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-sync-alt text-red-500 mr-2 mt-1"></i>
                                <span>自旋的CPU资源浪费</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="p-6 bg-yellow-50 rounded-lg">
                        <div class="flex items-center mb-4">
                            <div class="icon-box bg-yellow-100 text-yellow-600">
                                <i class="fas fa-microchip"></i>
                            </div>
                            <h3 class="text-xl font-semibold ml-3">资源消耗增加</h3>
                        </div>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-memory text-yellow-500 mr-2 mt-1"></i>
                                <span>内存占用增加</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-battery-quarter text-yellow-500 mr-2 mt-1"></i>
                                <span>CPU利用率降低</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-project-diagram text-yellow-500 mr-2 mt-1"></i>
                                <span>锁的粒度与资源冲突</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="p-6 bg-blue-50 rounded-lg">
                        <div class="flex items-center mb-4">
                            <div class="icon-box bg-blue-100 text-blue-600">
                                <i class="fas fa-clock"></i>
                            </div>
                            <h3 class="text-xl font-semibold ml-3">系统响应时间延长</h3>
                        </div>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-hourglass-half text-blue-500 mr-2 mt-1"></i>
                                <span>线程阻塞与唤醒的延迟</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-running text-blue-500 mr-2 mt-1"></i>
                                <span>锁竞争的加剧</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-truck-loading text-blue-500 mr-2 mt-1"></i>
                                <span>吞吐量的减少</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="mt-8">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">系统稳定性受损</h3>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-white p-6 rounded-lg border border-gray-200">
                            <h4 class="font-medium mb-3 text-purple-600">锁饥饿问题</h4>
                            <p class="text-gray-700">在高并发环境下，重量级锁的使用可能导致某些线程长时间无法获取锁，导致锁饥饿问题。这不仅影响系统的稳定性，还可能导致数据不一致。</p>
                        </div>
                        
                        <div class="bg-white p-6 rounded-lg border border-gray-200">
                            <h4 class="font-medium mb-3 text-indigo-600">负载波动与系统抖动</h4>
                            <p class="text-gray-700">当大量锁从轻量级状态膨胀为重量级锁时，系统资源会突然涌向锁的管理和线程调度，导致其他业务逻辑的资源被抢占，引发系统抖动。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Optimization Section -->
    <section class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 text-center section-title">锁膨胀升级的优化策略</h2>
            
            <div class="card p-8">
                <div class="mb-12">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">合理设计锁的粒度</h3>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h4 class="font-medium mb-3 text-green-600 flex items-center">
                                <i class="fas fa-puzzle-piece mr-2"></i> 细粒度锁替代粗粒度锁
                            </h4>
                            <p class="text-gray-700">通过细化锁的粒度，即将一个大范围的锁拆分为多个小范围的锁，可以减少线程之间的竞争。例如使用分段锁(Segmented Lock)来对不同部分的数据加锁。</p>
                        </div>
                        
                        <div>
                            <h4 class="font-medium mb-3 text-green-600 flex items-center">
                                <i class="fas fa-compress-arrows-alt mr-2"></i> 减少临界区的大小
                            </h4>
                            <p class="text-gray-700">通过缩小临界区的大小，可以减少线程持有锁的时间。将复杂的计算或业务逻辑放在同步代码块之外，确保同步代码块内的操作尽可能简单和快速。</p>
                        </div>
                    </div>
                </div>
                
                <div class="mb-12">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">优化锁的使用方式</h3>
                    
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="bg-white p-5 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-3">
                                <div class="icon-box bg-blue-100 text-blue-600">
                                    <i class="fas fa-ban"></i>
                                </div>
                                <h4 class="font-medium ml-3">避免不必要的锁</h4>
                            </div>
                            <p class="text-sm text-gray-700">避免为每一个共享资源都加锁，而是选择性地对真正需要保护的资源进行同步，或使用无锁编程技术。</p>
                        </div>
                        
                        <div class="bg-white p-5 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-3">
                                <div class="icon-box bg-purple-100 text-purple-600">
                                    <i class="fas fa-book-reader"></i>
                                </div>
                                <h4 class="font-medium ml-3">使用读写锁</h4>
                            </div>
                            <p class="text-sm text-gray-700">在读多写少的场景下，使用读写锁(ReentrantReadWriteLock)来替代传统的互斥锁，提升系统的并发性能。</p>
                        </div>
                        
                        <div class="bg-white p-5 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-3">
                                <div class="icon-box bg-yellow-100 text-yellow-600">
                                    <i class="fas fa-spinner"></i>
                                </div>
                                <h4 class="font-medium ml-3">自旋锁的合理使用</h4>
                            </div>
                            <p class="text-sm text-gray-700">在锁竞争不激烈且持有时间短的场景中使用自旋锁，设置合理的自旋次数或使用JVM的自适应自旋锁机制。</p>
                        </div>
                    </div>
                </div>
                
                <div class="mb-12">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">采用无锁数据结构</h3>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h4 class="font-medium mb-3 text-blue-600 flex items-center">
                                <i class="fas fa-database mr-2"></i> 无锁数据结构
                            </h4>
                            <p class="text-gray-700">使用java.util.concurrent包中的无锁队列(如ConcurrentLinkedQueue)来替代传统的同步队列，减少锁膨胀的风险。</p>
                        </div>
                        
                        <div>
                            <h4 class="font-medium mb-3 text-blue-600 flex items-center">
                                <i class="fas fa-code mr-2"></i> 无锁编程范式
                            </h4>
                            <p class="text-gray-700">通过避免使用锁而实现线程安全的编程技术，依赖于CAS操作，适用于高并发、低延迟的场景。</p>
                        </div>
                    </div>
                </div>
                
                <div class="mb-12">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">优化JVM参数配置</h3>
                    
                    <div class="overflow-x-auto">
                        <table class="min-w-full bg-white rounded-lg overflow-hidden">
                            <thead class="bg-gray-100">
                                <tr>
                                    <th class="py-3 px-4 text-left text-sm font-medium text-gray-700">参数</th>
                                    <th class="py-3 px-4 text-left text-sm font-medium text-gray-700">作用</th>
                                    <th class="py-3 px-4 text-left text-sm font-medium text-gray-700">推荐值</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-gray-200">
                                <tr>
                                    <td class="py-3 px-4 text-sm text-gray-700 font-mono">-XX:BiasedLockingStartupDelay</td>
                                    <td class="py-3 px-4 text-sm text-gray-700">控制偏向锁的延迟</td>
                                    <td class="py-3 px-4 text-sm text-gray-700">根据应用场景调整</td>
                                </tr>
                                <tr>
                                    <td class="py-3 px-4 text-sm text-gray-700 font-mono">-XX:-UseBiasedLocking</td>
                                    <td class="py-3 px-4 text-sm text-gray-700">禁用偏向锁</td>
                                    <td class="py-3 px-4 text-sm text-gray-700">高并发场景可考虑禁用</td>
                                </tr>
                                <tr>
                                    <td class="py-3 px-4 text-sm text-gray-700 font-mono">-XX:PreBlockSpin</td>
                                    <td class="py-3 px-4 text-sm text-gray-700">设置自旋次数</td>
                                    <td class="py-3 px-4 text-sm text-gray-700">10-100次</td>
                                </tr>
                                <tr>
                                    <td class="py-3 px-4 text-sm text-gray-700 font-mono">-XX:+UseThreadPriorities</td>
                                    <td class="py-3 px-4 text-sm text-gray-700">启用线程优先级</td>
                                    <td class="py-3 px-4 text-sm text-gray-700">视情况开启</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">架构层面的优化</h3>
                    
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="bg-white p-5 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-3">
                                <div class="icon-box bg-green-100 text-green-600">
                                    <i class="fas fa-share-alt"></i>
                                </div>
                                <h4 class="font-medium ml-3">减少共享资源</h4>
                            </div>
                            <p class="text-sm text-gray-700">通过数据分区或分片策略，将数据划分到不同的节点或分片中，减少对单一资源的访问。</p>
                        </div>
                        
                        <div class="bg-white p-5 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-3">
                                <div class="icon-box bg-indigo-100 text-indigo-600">
                                    <i class="fas fa-envelope-open-text"></i>
                                </div>
                                <h4 class="font-medium ml-3">消息队列解耦</h4>
                            </div>
                            <p class="text-sm text-gray-700">使用消息队列实现异步处理，避免多个线程同时争抢锁，减少锁膨胀的可能性。</p>
                        </div>
                        
                        <div class="bg-white p-5 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-3">
                                <div class="icon-box bg-purple-100 text-purple-600">
                                    <i class="fas fa-project-diagram"></i>
                                </div>
                                <h4 class="font-medium ml-3">微服务架构</h4>
                            </div>
                            <p class="text-sm text-gray-700">将单体应用拆分为多个独立的服务，减少不同业务模块之间的锁竞争。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            fontFamily: 'Noto Sans SC, sans-serif',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动到锚点
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
        
        // 卡片悬停效果
        document.querySelectorAll('.card').forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.transform = 'translateY(-4px)';
                this.style.boxShadow = '0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05)';
            });
            card.addEventListener('mouseleave', function() {
                this.style.transform = '';
                this.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1)';
            });
        });
    </script>
</body>
</html>
```